' This sample script shows how to apply 3 different filters to
' selections in the open document. Adjust the file path for the
' FileName variable as needed to open an appropriate file

Private Sub Command1_Click()

  Dim appRef As Photoshop.Application
  Dim docRef As Photoshop.Document
  Dim textureType As Photoshop.PsTextureType
  Dim selectionType As Photoshop.PsSelectionType
  Dim FileName As String
  Dim strtRulerUnits As Photoshop.PsUnits

  Set appRef = New Photoshop.Application
  
  ' We don't want any Photoshop dialogs displayed during
  'automated execution
  appRef.DisplayDialogs = psDisplayNoDialogs
  
  ' We are going to use pixel value inputs, so we need to ensure that
  ' the current ruler units in Preferences is pixels
  strtRulerUnits = appRef.Preferences.RulerUnits
  appRef.Preferences.RulerUnits = psPixels

  FileName = appRef.Path & "Samples\Dune.tif"
  Set docRef = appRef.Open(FileName)
  
  ' Make 3 different selections and apply different filters.
  docRef.Selection.Select Array(Array(0, 485), Array(600, 485), Array(600, 600), Array(0, 600)), Feather:=20, AntiAlias:=True
  docRef.ArtLayers(1).ApplyAddNoise 15, psGaussianNoise, False
    
  docRef.Selection.Select Array(Array(120, 20), Array(210, 20), Array(210, 110), Array(120, 110)), Feather:=15, AntiAlias:=False
  docRef.ActiveLayer.ApplyDiffuseGlow graininess:=9, glowAmount:=12, clearAmount:=15
    
  textureType = psTinyLensTexture
  docRef.ActiveLayer.ApplyGlassEffect Distortion:=7, Smoothness:=3, Scaling:=7, Invert:=False, texture:=textureType, textureFile:=Nothing
    
  docRef.Selection.Deselect

  'Set ruler units back the way we found it
  appRef.Preferences.RulerUnits = strtRulerUnits

End Sub
